<?php

/*
 * Lapsevanema Nimi
Lapse Nimi
E-post
Telefon
Lapse sünnikuupüev (pp.kk.aaaa)
Lisainfo
 * 
 */


class SimpleContactForm extends sfForm{

   public function configure()
   {

     sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));

     $this->setNameFormat();

     $this->widgetSchema['parent'] = new sfWidgetFormInput();
     $this->widgetSchema['child'] = new sfWidgetFormInput();
     $this->widgetSchema['birthday'] = new sfWidgetFormDateJQueryUI(array("change_year" => true));
     $this->widgetSchema['email'] = new sfWidgetFormInput();
     $this->widgetSchema['phone'] = new sfWidgetFormInput();
     $this->widgetSchema['message'] = new sfWidgetFormTextarea();
     $this->widgetSchema['captcha'] = new sfWidgetFormInput();

	 
     $this->setValidators( array(
        'parent' => new sfValidatorString(array('required' => true,'min_length' => 3, 'max_length' => 100), array('required' => __('parents name is required'))),
        'child' => new sfValidatorString(array('required' => true,'min_length' => 3, 'max_length' => 100), array('required' => __('childs name is required'))),
        'email' => new sfValidatorEmail(array('required' => true,'max_length' => 100), array('invalid' => __('wrong email'), 'required' => __('email is required'))),
        'birthday' => new sfValidatorDate(array('required' => true), array('invalid' => __('invalid birthday date'), 'required' => __('childs birthday is required'))),
        'phone' => new sfValidatorString(array('required' => false,'min_length' => 0, 'max_length' => 100), array('required' => __('phone number is required'))),
        'message' => new sfValidatorString(array('required' => false,'min_length' => 0, 'max_length' => 700), array('required' => __('message is required'))),
     	'captcha' => new sfCaptchaGDValidator(array('length' => 4), array('invalid' => 'wrong captcha code')),
      ));

	 
	 $this->getWidgetSchema()->setLabels(array(
		 'parent' => __('Parents name'),
		 'child' => __('Childs name'),
		 'birthdate' => __('Childs birthday'),
		 'email' => __('Email'),
		 'phone' => __('Phone'),
		 'message' => __('Message'),
		 'captcha' => __('Captcha')
	 ));

   }


   public function setNameFormat(){
        $this->widgetSchema->setNameFormat('contact[%s]');
   }

   public function validateForm(sfWebRequest $request){
       $this->bind($request->getParameter($this->getName()), array());

       if($this->isValid()){
           return true;
       }else{
           return false;
       }

   }

   public function getErrors(){
   $result = array();

    foreach($this->getErrorSchema() as $index => $val){
        $result[$index] = $val->__toString();
    }
    return $result;
    
   }


}
